
package co.yixiang.modules.shop.web.controller;

import co.yixiang.annotation.AnonymousAccess;
import co.yixiang.common.api.ApiResult;
import co.yixiang.modules.shop.entity.AppVersion;
import co.yixiang.modules.shop.service.AppVersionService;
import co.yixiang.modules.shop.web.vo.AppVersionVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 接口限流测试类
 */
@RestController
@Api(value = "投资端:版本检查", tags = "投资端:版本检查", description = "投资端:版本检查")
public class AppVersionController {
    private static final AtomicInteger ATOMIC_INTEGER = new AtomicInteger();
    @Autowired
    private AppVersionService appVersionService;


    @AnonymousAccess
    @GetMapping("/versionCheck")
    @ApiOperation(value = "版本检查", notes = "版本检查")
    public ApiResult<AppVersion> versionCheck( String version) {
         List<AppVersion> list = appVersionService.findVersion(1);
        AppVersionVo appVersionVo = new AppVersionVo();
        if(list != null && list.size() >0){
            AppVersion appVersion =  list.get(0);
            appVersionVo.setPkgUrl(appVersion.getPkgUrl());
            appVersionVo.setWgtUrl(appVersion.getWgtUrl());
            appVersionVo.setVersion(appVersion.getVersion());
            System.out.print("=="+version);
            if(!version.equals(appVersion.getVersion())){
                appVersionVo.setUpdate(true);
            }
            else{
                appVersionVo.setUpdate(false);
            }
        }else{
            appVersionVo.setUpdate(false);
        }


        return ApiResult.ok(appVersionVo);
    }
}
